﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ahp;

namespace AhpTest
{
    [TestClass]
    public class AlternativeCollectionTest
    {
        [TestMethod]
        public void AddAlternativeTest()
        {
            AlternativeCollection alternatives = new AlternativeCollection();
            Alternative alternative = new Alternative("Alternative");

            int index = alternatives.Add(alternative);

            Assert.AreEqual(0, index);
            Assert.AreEqual(alternative, alternatives[index]);

            //no repeated elements
            index = alternatives.Add(alternative);
            Assert.AreEqual(0, index);
            Assert.AreEqual(1, alternatives.Count);
        }

        [TestMethod]
        public void CreateAndAddAlternativeTest()
        {
            AlternativeCollection alternatives = new AlternativeCollection();
            Alternative alternative = alternatives.Add("Alternative");

            Assert.AreEqual(alternative, alternatives[0]);
            Assert.AreEqual("Alternative", alternative.Name);
        }

        [TestMethod]
        public void RemoveAlternativeTest()
        {
            AlternativeCollection alternatives = new AlternativeCollection();
            Alternative alternative = new Alternative();

            alternatives.Add(alternative);
            Assert.IsTrue(alternatives.Contains(alternative));

            alternatives.Remove(alternative);
            Assert.IsFalse(alternatives.Contains(alternative));
        }

        [TestMethod]
        public void ClearAlternativesTest()
        {
            AlternativeCollection alternatives = new AlternativeCollection();
            Alternative alternative1 = new Alternative();
            Alternative alternative2 = new Alternative();

            alternatives.Add(alternative1);
            alternatives.Add(alternative2);
            Assert.AreEqual(2, alternatives.Count);

            alternatives.Clear();
            Assert.AreEqual(0, alternatives.Count);
        }
    }
}
